/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 09 - 20
 * Time: 17:03
 */

import java.util.concurrent.*;

/**
 * 使用ThreadPoolExecutor创建一个忽略最新任务的线程池，创建规则：
 *         1.核心线程数为5
 *         2.最大线程数为10
 *         3.任务队列为100
 *         4.拒绝策略为忽略最新任务
 */
public class Demo10 {
    public static void main(String[] args) {
        ThreadPoolExecutor.DiscardPolicy discardPolicy = new ThreadPoolExecutor.DiscardPolicy();
        ExecutorService service = new ThreadPoolExecutor(5, 10, 5,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(100), discardPolicy);
        for (int i = 0; i < 10; i++) {
            int id = i;
            service.submit(() -> {
                System.out.print(id + " ");
            });
        }
    }
}
